#include <ani.h>
#include <iostream>

#include "constant.h"
#include "log.h"
#include "ani_task.h"
#include "request_manager.h"

using namespace OHOS::Request;

int32_t AniTask::Create(Config config)
{
    int32_t seq = RequestManager::GetInstance()->GetNextSeq();
    REQUEST_HILOGD("AniTask::Create: seq: %{public}d", seq);
    if (!RequestManager::GetInstance()->LoadRequestServer()) {
        REQUEST_HILOGE("End create task in JsTask CreateExec, seq: %{public}d, failed: request service "
                       "not ready", seq);
        return E_SERVICE_ERROR;
    }
    // if (context->task->config_.mode == Mode::FOREGROUND) {
    //     RegisterForegroundResume();
    // }
    std::string tid = "tid";
    int32_t ret = RequestManager::GetInstance()->Create(config, seq, tid);
    if (ret != E_OK) {
        REQUEST_HILOGE("End create task in JsTask CreateExec, seq: %{public}d, failed: %{public}d", seq, ret);
        return ret;
    }

    return 0;
}

void AniTask::Start() {
    std::cout << "Enter AniTask::Start" << std::endl;
    REQUEST_HILOGI("Enter AniTask::Start");
    
    RequestManager::GetInstance()->Start(tid_);
}

void AniTask::On() {
    std::cout << "Enter AniTask::On" << std::endl;
    REQUEST_HILOGI("Enter AniTask::On");
}
